@echo off
setlocal enabledelayedexpansion

echo =======================================================
echo          License Key Generator (Admin Only)
echo =======================================================
echo.

REM Secret key
set "SECRET_KEY=XHS-LICENSE-2024-SECURE-KEY-FOR-GENERATION"

:start_input
echo Please enter the machine code to generate license key
echo.
set /p "machine_code=Machine Code: "

if "!machine_code!"=="" (
    echo.
    echo Error: Machine code cannot be empty!
    goto start_input
)

:generate_license
echo.
echo Generating license key...
echo.

REM Combine machine code and secret key
set "combined_data=!machine_code!:!SECRET_KEY!"

REM Use PowerShell to generate SHA256 hash
for /f "delims=" %%i in ('powershell -ExecutionPolicy Bypass -Command "$data='!combined_data!'; $bytes=[System.Text.Encoding]::UTF8.GetBytes($data); $hash=[System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes); ($hash | ForEach-Object { $_.ToString('x2') }) -join ''"') do set "license_hash=%%i"

REM Check if hash was generated successfully
if "!license_hash!"=="" (
    echo Warning: SHA256 generation failed, using fallback method.
    REM Fallback: use a simple hash based on machine code
    set "license_hash=!machine_code!!SECRET_KEY!"
    set "license_hash=!license_hash:-=!"
    set "license_hash=!license_hash::=!"
    set "license_hash=!license_hash!0123456789abcdef0123456789abcdef0123456789abcdef"
    set "license_hash=!license_hash:~0,40!"
)

echo.
echo =======================================================
echo               License Key Generated
echo =======================================================
echo.
echo Machine Code: !machine_code!
echo License Key:  !license_hash!
echo.
echo =======================================================
echo.

:end_program
echo.
echo License key generator exited.
pause
exit /b 0 